from StartGroup.models import Group
from groupevents.models import Events, Event_Comment
from django import forms
from django.conf import settings
from django import forms
import datetime
from django.forms.extras.widgets import SelectDateWidget
from datetime import date
from utils.widgets import DatePicker

attrs_dict = { 'class': 'required' }

class CreateEventForm(forms.Form):
    
    event_name = forms.CharField(max_length=25, required=True, label='EVENT NAME', error_messages={'required': 'Please enter Event Name'},
                                widget=forms.TextInput(attrs={'size':'25', 'id':'id_event_name'}))
    event_place = forms.CharField(max_length=25, required=True, label='PLACE', error_messages={'required': 'Please enter a place for event'},
                                widget=forms.TextInput(attrs={'size':'25', 'id':'id_event_place'}))
    event_desc = forms.CharField(max_length=100, required=False, label='DESCRIPTION',
                                 widget=forms.Textarea(attrs={'size':'100', 'cols':'100', 'rows':'3', 'id':'id_event_desc'}))
    event_date = forms.DateTimeField(required=True, label='DATE', error_messages={'required': 'Please enter Date and Time of the event'},
                                 widget=DatePicker())

    
    def save(self, user_id, group_info):
        new_group_event = Events(group = group_info,
                                event_name=self.cleaned_data['event_name'],
                                event_place=self.cleaned_data['event_place'],
                                event_desc=self.cleaned_data['event_desc'],
                                event_date=self.cleaned_data['event_date'],
                                post_by = user_id,
                                )
        new_group_event.save()
        return new_group_event


class PostEventCommentForm(forms.Form):
    
    comment = forms.CharField(max_length=200, required=True, label='COMMENT', error_messages={'required': 'Please enter a place for event'},
                                widget=forms.Textarea(attrs={'size':'200', 'cols':'100', 'rows':'2','id':'commentBoxId'}))

    post_date = datetime.date.today()

    def save(self, event_info, user_id, memberImgPath):
        comment_update = Event_Comment(event = event_info,
                                comment=self.cleaned_data['comment'],
                                post_by = user_id,
                                photo = memberImgPath
                                )
        comment_update.save()
        return comment_update
